param(
	[string]$option = "$(Read-Host 'Enter the operation options:')",
	[string]$siteCollectionUrl = "http://turnersintranet/sites/dms",
	[string]$year = "",
	[string]$gatsCaSourceFile = "D:\Document Types\GAT\FinanceDocExport_18_05_2012_edit2.csv",
	[string]$gatsSourceFolder = "D:\Document Types\GAT\2012",
	[string]$caSourceFolder = "D:\Document Types\Credit Application\2012",
	[string]$invoiceCsvSource = "",
	[string]$invoiceSourceFolder = "" 
)

if(!$siteCollectionUrl.EndsWith("/")){
	$siteCollectionUrl = $siteCollectionUrl + "/"
}

$gatsWebUrl = $siteCollectionUrl + "GATs"
$caWebUrl =  $siteCollectionUrl + "CreditApplications"
$invoiceWebUrl = $siteCollectionUrl + "invoices"

	#option 4,5 only

	#option 6

if($option -eq 1){
 #Delete All GAT and Credit Applications Data.
 .\DeleteAllGATCA.ps1 -gatWebUrl $gatsWebUrl -caWebUrl $caWebUrl
 
}elseif($option -eq 2){
	if(!$year)
	{
		Write-Host "Year is required to execute option 2" -ForegroundColor Red
		return
	}
	#Delete All Invocies Data (enter the year to delete). 
	$invoiceWebYearUrl = $invoiceWebUrl + "/" + $year
	.\DeleteAllDocs.ps1 -invoiceWebYearUrl  $invoiceWebYearUrl
}elseif($option -eq 3){
	#Clean Import GAT and Credit Application.

Write-Host "Cleaning data in gats and ca lists..."
.\DeleteAllGATCA.ps1 -gatWebUrl $gatsWebUrl -caWebUrl $caWebUrl
Write-Host "Importing data in gats and ca lists..."
.\ImportGATCA.ps1 -csvSource $gatsCaSourceFile -sourceFolderGats $gatsSourceFolder -sourceFolderCa $caSourceFolder -gatWebUrl $gatsWebUrl -caWebUrl $caWebUrl
	
}elseif($option -eq 4){
	#Incremental Import GAT and Credit Application.

	.\ImportGATCA.ps1 -csvSource $gatsCaSourceFile -sourceFolderGats $gatsSourceFolder -sourceFolderCa $caSourceFolder -gatWebUrl $gatsWebUrl -caWebUrl $caWebUrl
}elseif($option -eq 5){
	#Clean Create Invoice Site and Import Invoices.
	if(!$year)
	{
		Write-Host "Year is required to execute option 5" -ForegroundColor Red
		return
	}
	Write-Host $invoiceSourceFolder
	.\createInvoiceSite.ps1 -invoiceRootSiteUrl $invoiceWebUrl -invoiceYear $year -forceDeleteExistingSite 1
	.\ImportInvoices.ps1 -dmsWebUrl $siteCollectionUrl -csvSource $invoiceCsvSource -invoiceSourceFolder $invoiceSourceFolder -invoiceWebUrl $invoiceWebUrl -importYear $year
}elseif($option -eq 6){
	#Incremental Create and Import Invoices.
	if(!$year)
	{
		Write-Host "Year is required to execute option 6" -ForegroundColor Red
		return
	}
	.\ImportInvoices.ps1 -dmsWebUrl $siteCollectionUrl -csvSource $invoiceCsvSource -invoiceSourceFolder $invoiceSourceFolder -invoiceWebUrl $invoiceWebUrl -importYear $year

}else{
	Write-Host "Option is not valid. Script completed." -ForegroundColor Red
}


